﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using TrainingCenterSystem;
using TrainingCenterSystem.UserManagement;

namespace TrainingCenterWinClient.Forms
{
    public partial class LanguageSelectForm : Form
    {
        private TrainingCenter _trainingCenter;
        public LanguageSelectForm()
        {
            InitializeComponent();
            _trainingCenter = new TrainingCenter();
            this.initLanguages();
        }

        private void initLanguages()
        {
            for (int i=0;i<_trainingCenter.AvailableLanguages.Length;i++)
                this.cmbLanguageSelect.Items.Add(_trainingCenter.AvailableLanguages[i]);
            this.cmbLanguageSelect.SelectedIndex=0;

            this.cmbLanguageSelect.Enabled = false;
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void cmbLanguageSelect_KeyDown(object sender, KeyEventArgs e)
        {
            e.Handled=true;
        }

        private void cmbLanguageSelect_KeyDown(object sender, KeyPressEventArgs e)
        {

        }

        private void btnSelectLanguage_Click(object sender, EventArgs e)
        {
            if (this.cmbLanguageSelect.SelectedIndex == -1)
                return;

            // for the basic version only
            if (_trainingCenter.IsBasicVersion)
            {
                _trainingCenter.SetLanguage(0); // set the language to English
                User aUser = new Supervisor("0001","basicUser","basic@user.se"); // create a dummy user
                _trainingCenter.CurrentUser = aUser;
                _trainingCenter.AvailableUsers.Add(aUser);
                MainForm mf = new MainForm(_trainingCenter, this);
                mf.Show();
                this.Hide();
                return;

            }
            else
                _trainingCenter.SetLanguage(this.cmbLanguageSelect.SelectedIndex);
                        
            LoginForm loginForm = new LoginForm(_trainingCenter);
            loginForm.Show();            

            this.Hide();

            //MainForm mainForm = new MainForm(_trainingCenter, this);
            //mainForm.Show();            
            
        }

        private void LanguageSelectForm_Load(object sender, EventArgs e)
        {

        }
    }
}
